<template>
  <div>
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @cancel="$emit('close')"
      @confirm="confirm"
    />
  </div>
</template>

<script>
import moment from 'moment'
import { editUserInfo } from '@/api/user.js'
export default {
  name: 'BirthPup',
  props: {
    birth: {
      type: String,
      required: true
    }
  },
  data () {
    return {
      minDate: new Date(1900, 0, 1),
      maxDate: new Date(2080, 10, 1),
      currentDate: new Date(this.birth)
    }
  },
  methods: {
    async confirm () {
      await editUserInfo({
        birthday: moment(this.currentDate).format('YYYY-MM-DD')
      })
      this.$toast('修改生日成功')
      this.$emit('editBirth', moment(this.currentDate).format('YYYY-MM-DD'))
    }
  }
}
</script>

<style></style>
